<%--
  Created by IntelliJ IDEA.
  User: XPS15
  Date: 2022/2/28
  Time: 10:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" +
          request.getServerPort() + path + "/";
%>
<base href="<%=basePath%>">
<html>
  <head>
    <script src="<%=basePath%>js/jquery-1.8.3.min.js"></script>
    <title>登录</title>
  </head>
  <body>
  <tr>${msg}</tr>
  <table style="border: 0;margin-left: 40%;margin-top: 200px">
    <tr>
      <td><label for="phone">用户名/手机号:</label></td>
      <td><input type="text" name="phone" id="phone" required="required" value="" /></td>
    </tr>
    <tr>
      <td><label for="password">密码:</label></td>
      <td><input type="password" name="password" required="required" id="password" value="" /></td>
    </tr>
  </table>
  <input style="margin-left: 45%;margin-top: 10px" type="button" value="登录" onclick="login()" />
  </body>
<script>

function login(){
  var phone = $("#phone").val();
  var pwd = $("#password").val();
  $.ajax({
    async:false,
    type:"POST",
    url:"/myweb/userServlet",
    data:{
      phone:phone,
      pwd:pwd,
      con:"login"
    },
    success:function(res){
      if(res == "yes"){
        //登录成功跳转到主页
        window.location.href = "/myweb/userServlet?con=show";
        /*$.ajax({
          type:"post",
          url:"/myweb/userServlet",
          data:{
            con:"show"
          }
        })*/
      }
      if(res == "noname"){
        alert("用户名不存在");
        return;
      }
      if(res == "pwderr"){
        alert("密码错误")
        return;
      }
  }
  })


}

</script>
</html>
